<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>02绘制矩形</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        canvas{
            border: 1px solid #000;
        }
    </style>
</head>
<body>
  <canvas height="400px" width="600px">

  </canvas>
</body>
</html>

<script>
    // 获取canvas元素
    let canvas = document.querySelector('canvas');
    // 获取绘图上下文
    let ctx = canvas.getContext('2d');
    // 绘制矩形(x,y,width,height)
    ctx.strokeStyle = 'red';// 设置颜色
    ctx.strokeRect(100,100,300,100);
    ctx.fillStyle = 'cyan';// 设置颜色
    ctx.fill();  // 设置填充
    // 填充矩形(x,y,width,height)
    ctx.fillRect(200,200,300,100);
</script>
